Skip to content

request audio focus when recording voice messages#6194

Merged
bmarty merged 5 commits intoelement-hq:developfrom
vmfunc:feature/audio-focus-voice-recording
Feb 23, 2026
Merged

request audio focus when recording voice messages#6194
bmarty merged 5 commits intoelement-hq:developfrom
vmfunc:feature/audio-focus-voice-recording

Conversation

@vmfunc
Copy link
Contributor

@vmfunc vmfunc commented Feb 12, 2026

recording a voice message now requests audio focus; background media
(spotify, deezer, etc.) gets paused while recording and resumes when
you stop. matches the behavior of signal and whatsapp.

the AudioFocus infrastructure was already in place for playback
(DefaultMediaPlayer uses it), just wasn't wired into the recording path.

fixes #5997

Signed-off-by: vmfunc <celeste@linux.com>
@vmfunc vmfunc requested a review from a team as a code owner February 12, 2026 15:35
@vmfunc vmfunc requested review from ganfra and removed request for a team February 12, 2026 15:35
@github-actions
Copy link
Contributor

Thank you for your contribution! Here are a few things to check in the PR to ensure it's reviewed as quickly as possible:

  • Your branch should be based on origin/develop, at least when it was created.
  • The title of the PR will be used for release notes, so it needs to describe the change visible to the user.
  • The test pass locally running ./gradlew test.
  • The code quality check suite pass locally running ./gradlew runQualityChecks.
  • If you modified anything related to the UI, including previews, you'll have to run the Record screenshots GH action in your forked repo: that will generate compatible new screenshots. However, given Github Actions limitations, it will prevent the CI from running temporarily, until you upload a new commit after that one. To do so, just pull the latest changes and push an empty commit.

@CLAassistant
Copy link

CLAassistant commented Feb 12, 2026

CLA assistant check
All committers have signed the CLA.

@github-actions github-actions bot added the Z-Community-PR Issue is solved by a community member's PR label Feb 12, 2026
Copy link
Member

@bmarty bmarty left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the PR. Looks good, if you have time to check what's happening when the audio focus is lost while recording a voice message, that would be awesome.


private fun CoroutineScope.startRecording() = launch {
try {
audioFocus.requestAudioFocus(AudioFocusRequester.VoiceMessage) {}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In the case of a voice recording, willPausedWhenDucked should maybe return false?
Maybe create a new AudioFocusRequester.RecordVoiceMessage to handle this case.
Also the second parameter onFocusLost should maybe do something like stopping the recording?

Maybe worth checking the behavior when a voice message is getting recorded and an audio stream is (re)started (from a notification for instance).

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yeah good call on all of these, pushed two more commits.

added RecordVoiceMessage as a separate requester with willPausedWhenDucked = false - no audio output to duck when recording, and this way notification sounds won't trigger transient focus loss and kill the recording. only actual focus loss (phone call etc) stops it.

onFocusLost now finishes the recording and leaves the partial result in preview state so nothing gets lost.

haven't tested the notification audio restart on device yet but with willPausedWhenDucked = false those events shouldn't reach us at all.

separates recording from playback focus - willPausedWhenDucked is false
for recording so notification sounds don't interrupt mid-recording

Signed-off-by: vmfunc <celeste@linux.com>
if something else grabs focus mid-recording (phone call, etc), stop
the recording and keep the partial result in preview state instead
of silently recording garbage

Signed-off-by: vmfunc <celeste@linux.com>
@vmfunc vmfunc requested a review from bmarty February 12, 2026 17:40
@codecov
Copy link

codecov bot commented Feb 12, 2026

Codecov Report

❌ Patch coverage is 61.53846% with 5 lines in your changes missing coverage. Please review.
✅ Project coverage is 81.41%. Comparing base (6bdb9c7) to head (b8099ad).
⚠️ Report is 46 commits behind head on develop.

Files with missing lines Patch % Lines
.../android/libraries/audio/impl/DefaultAudioFocus.kt 0.00% 3 Missing ⚠️
...FakeDefaultVoiceMessageComposerPresenterFactory.kt 33.33% 2 Missing ⚠️
Additional details and impacted files
@@             Coverage Diff             @@
##           develop    #6194      +/-   ##
===========================================
- Coverage    81.41%   81.41%   -0.01%     
===========================================
  Files         2569     2569              
  Lines        69701    69711      +10     
  Branches      8942     8942              
===========================================
+ Hits         56750    56754       +4     
- Misses        9630     9637       +7     
+ Partials      3321     3320       -1     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

per review feedback - need true here so the onFocusLost callback
actually fires on all Android versions

Signed-off-by: vmfunc <celeste@linux.com>
@vmfunc vmfunc requested a review from bmarty February 12, 2026 21:08
@vmfunc
Copy link
Contributor Author

vmfunc commented Feb 13, 2026

hey @bmarty seems ready for review - codecov fails but after digging i doubt it comes from my end

@vmfunc
Copy link
Contributor Author

vmfunc commented Feb 23, 2026

sorry for bumping this. any issues with this PR?

Copy link
Member

@bmarty bmarty left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the update!

@bmarty bmarty merged commit 1a99057 into element-hq:develop Feb 23, 2026
24 of 27 checks passed
@bmarty
Copy link
Member

bmarty commented Feb 23, 2026

sorry for bumping this. any issues with this PR?

Sorry for the delay, I was off last week. Thanks again for the PR!

@vmfunc
Copy link
Contributor Author

vmfunc commented Feb 23, 2026

all good, thank you!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Z-Community-PR Issue is solved by a community member's PR

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Recording an audio message should pause the current media playing

3 participants